﻿using System;
using System.Data;
using TraditionalMalteseCuisine.App_Code.Functions;
using TraditionalMalteseCuisine.App_Code.Objects;
using TraditionalMalteseCuisine.App_Code.Operations;

namespace TraditionalMalteseCuisine
{
    public partial class BoardLeadersInPostedRecipesComments : System.Web.UI.Page
    {
        #region Page Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        #endregion


        #region Events
        protected void cmbMaxRecords_SelectedIndexChanged(object sender, EventArgs e)
        {
            MaxRecords = int.Parse(cmbMaxRecords.SelectedValue.ToString());
            BindData();
        }
        #endregion


        #region Methods
        protected string GetContributionLevel(int memberID)
        {
            return Site_Functions.GetAwardLevelForRecipesCommentsPosted(Site_Functions.GetSiteMemberByID(memberID));
        }

        private void BindData()
        {
            try
            {
                DataTable dtLeaders = ReadOp.GetDataTable(SiteMember.GetCommand_GetTopContributorsInRecipesCommentsPosted(MaxRecords));

                cmbMaxRecords.SelectedValue = MaxRecords.ToString();

                rptLeaders.DataSource = dtLeaders;
                rptLeaders.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        #endregion


        #region Properties
        protected int MaxRecords
        {
            get { return ((Session["MaxRecords"] == null) ? 5 : (int)Session["MaxRecords"]); }
            set { Session["MaxRecords"] = value; }
        }
        #endregion
    }
}